﻿using System;
using Sitecore.Diagnostics;
using Sitecore.Shell.Framework.Commands;

namespace RedirectManager.Shell.Framework.Commands
{
    [Serializable]
    public class AddRedirect : Command
    {
        #region methods

        public override void Execute(CommandContext context)
        {
            Assert.ArgumentNotNull(context, "context");
            if ((context.Items.Length == 1) && context.Items[0].Access.CanWrite())
            {
                Start("uiAddRedirect", context.Items[0]);
            }
        }

        public override CommandState QueryState(CommandContext context)
        {
            if (context.Items.Length == 1)
            {
                var contextItem = context.Items[0];
                if (contextItem.Paths.IsContentItem && contextItem.Access.CanWrite())
                {
                    return base.QueryState(context);
                }
            }

            return CommandState.Disabled;
        }

        #endregion
    }
}
